/**
 * Created by linghong on 2018/12/24.
 */
//返回上一页
function go() {
    window.history.go(-1);
}

var userId = GetQueryString("userId");
var token = GetQueryString("token");
if(userId!=null&&token!=null){
    localStorage.setItem("userId", userId);
    localStorage.setItem("token", token);
}else{
    userId = localStorage.getItem("userId")
    token = localStorage.getItem("token")
}

var Url= "http://server.duoyizhibo.com";//正式环境
// var Url= "";//本地开发环境



//ajax封装
//type：请求方式   site：地址  parameter：传给后台的参数    callback：请求成功后执行的函数
function Hajax(type, site, parameter, callback) {
 
	$.ajax({
		type: type,
		url: Url + site,
		contentType: "application/json;charset=utf-8",
		data: parameter,
        async: false,
		dataType: "json",
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("token",token);
            XMLHttpRequest.setRequestHeader("userId", userId);
        },
		success: function(data) {
			console.log(data);
			 
			callback(data);  //调用callback并把data传进去
			
		},
        error:function(err) {
            console.log(err);
        }
	});
}





//弹窗
var popup = ((Text) => {
	$("body").append('<div class="tishi">' + Text + '<div><button class="popup-button">确定</button></div></div>');
	$(".tishi").css({
		"width": "5rem",
		"position": "fixed",
		"font-size": "0.24rem",
		"background": "#ffffff",
		"color": "#333333",
		"box-shadow": "1px 1px 20px #333333",
		"height": "2.5rem",
		"top": "26vh",
		"left": "18vw",
		"border-radius": "32px",
		"text-align": "center",
		"padding-top": ".7rem",
		"z-index": "999"
	});

	$(".popup-button").css({
		"width": "3rem",
		"height": ".5rem",
		"margin-top": ".5rem",
		"font-size": "0.24rem",
		"background": "#4483f4",
		"color": "#ffffff",
	})

	setTimeout(function() {
		first = null;
		$(".tishi").fadeOut(3000, function() {
			//		            	$(".tishi").remove();
		});
	}, 1000);

	$(".popup-button").click(() => {
		$(".tishi").remove();
	})

})



//如何获取地址栏后面的信息
function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) return unescape(r[2]);
	return null;
}










